Documentation for Users  2.0.6
Perception Toolbox for Virtual Reality (PTVR) Manual
2.3_place_objects_on_tangent_screen.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 ...\PTVR_Researchers\Python_Scripts\DEMOS\Screens\
4 2.3_place_objects_on_tangent_screen.py
5 
6 @author: eric castet
7 
8 Animation demo to show:
9 
10 How to place objects on a TANGENT screen with ...
11  - either a 2D spherical coordinate system ( here a perimetric system) : ...
12  set_perimetric_coordinates_on_screen (.
13  - or a 2D cartesian coordinate system (in meter units) : ...
14  set_cartesian_coordinates_on_screen ()
15 
16 Note: the origin of the Coordinate System (CS) is at the center of the black point
17  in front of you.
18 
19 
20 """
21 
22 
23 import PTVR.SystemUtils
24 import numpy as np
25 import PTVR.Visual as visual
29 
30 import PTVR.Stimuli.Color as color
31 
32 
33 PWD = PTVR.SystemUtils.PWD
34 
35 # do not comment out: username is used (among other things) to create the name of your results file.
36 username = "Eric"
37 
38 tangent_screen_radial_distance_m = 1 # in meters
39 tangent_screen_eccentricity = 60
40 tangent_screen_halfmeridian = 180
41 
42 height_of_headset = 1.2 # in meters
43 if username == "Eric":
44  height_of_headset = 1.2
45 viewpoint_Z = 0.7
46 head_viewpoint_position = np.array([0, height_of_headset, viewpoint_Z])
47 
48 
49 def place_objects_w_cartesian_CS(my_world, my_scene, my_screen):
50  for i in np.arange(0, 0.6, 0.1):
51  my_object = PTVR.Stimuli.Objects.Cube(
52  size_in_meters=0.05, color=color.RGBColor(r=0.5, b=0.9))
53  # CARTESIAN Coordinates
54  my_object.set_cartesian_coordinates_on_screen(my_2D_screen=my_screen,
55  x_local=i, y_local=i)
56  my_scene.place(my_object, my_world)
57 # ---------------------------------------------------------------------
58 
59 
60 def place_objects_w_perimetric_CS(my_world, my_scene, my_tangent_screen, my_ecc):
61  for HM_j in range(0, 360, 45):
62  my_object = PTVR.Stimuli.Objects.Cube(
63  size_in_meters=0.1, color=color.RGBColor(r=1))
64  # PERIMETRIC Coordinates
65  my_object.set_perimetric_coordinates_on_screen(
66  tangentscreen = my_tangent_screen,
67  eccentricity_local_deg = my_ecc,
68  half_meridian_local_deg = HM_j)
69 
70  my_scene.place(my_object, my_world)
71 # ---------------------------------------------------------------------
72 
73 
74 def main():
75  my_world = visual.The3DWorld(name_of_subject=username)
76 
77  # Coordinate TRANSFORMATIONS
78  my_world.translate_coordinate_system_along_global(head_viewpoint_position)
79  # my_world.rotate_coordinate_system_about_global_y (90)
80 
82 
83  my_viewpoint = PTVR.Stimuli.Objects.Sphere(
84  size_in_meters=np.array([0.1, 0.1, 0.1]))
85  # the default position of an object being np.array([0.0, 0.0, 0.0]),
86  # my_viewpoint will be at the ORIGIN of the CURRENT coordinate system.
87 
88  # Place white TS straight-ahead with CARTESIAN Coordinates
89  my_tangent_screen_white = PTVR.Stimuli.Objects.TangentScreen(
90  color=color.RGBColor(r=1, g=1, b=1))
91  my_tangent_screen_white.set_cartesian_coordinates(x=0.0, y=0,
92  z=tangent_screen_radial_distance_m)
93 
94  # Place other TS with PERIMETRIC Coordinates
95  my_tangent_screen_yellow = PTVR.Stimuli.Objects.TangentScreen(
96  color=color.RGBColor(r=1, g=1))
97  my_tangent_screen_yellow.set_perimetric_coordinates(
98  eccentricity=tangent_screen_eccentricity,
99  halfMeridian=tangent_screen_halfmeridian,
100  radialDistance=tangent_screen_radial_distance_m)
101  my_tangent_screen_orange = PTVR.Stimuli.Objects.TangentScreen(
102  color=color.RGBColor(r=1, g=0.5))
103  my_tangent_screen_orange.set_perimetric_coordinates(
104  eccentricity=tangent_screen_eccentricity,
105  halfMeridian=180 + tangent_screen_halfmeridian,
106  radialDistance=tangent_screen_radial_distance_m)
107 
108  # Place other TS with CARTESIAN Coordinates
109  my_tangent_screen_green = PTVR.Stimuli.Objects.TangentScreen(
110  color=color.RGBColor(g=1))
111  my_tangent_screen_green.set_cartesian_coordinates(x=0, y=- tangent_screen_radial_distance_m,
112  z=tangent_screen_radial_distance_m)
113 
114  my_tangent_screen_blue = PTVR.Stimuli.Objects.TangentScreen(
115  color=color.RGBColor(b=1))
116  my_tangent_screen_blue.set_cartesian_coordinates(x=0, y=tangent_screen_radial_distance_m,
117  z=tangent_screen_radial_distance_m)
118 
119  my_scene.place(my_viewpoint, my_world)
120 
121  my_scene.place(my_tangent_screen_white, my_world)
122  my_scene.place(my_tangent_screen_yellow, my_world)
123  my_scene.place(my_tangent_screen_orange, my_world)
124  my_scene.place(my_tangent_screen_green, my_world)
125  my_scene.place(my_tangent_screen_blue, my_world)
126 
127  # place objects with 2D cartesian coordinates on the tangent screens
128  place_objects_w_cartesian_CS(my_world=my_world, my_scene=my_scene,
129  my_screen=my_tangent_screen_white)
130  place_objects_w_cartesian_CS(my_world=my_world, my_scene=my_scene,
131  my_screen=my_tangent_screen_yellow)
132  place_objects_w_cartesian_CS(my_world=my_world, my_scene=my_scene,
133  my_screen=my_tangent_screen_orange)
134  place_objects_w_cartesian_CS(my_world=my_world, my_scene=my_scene,
135  my_screen=my_tangent_screen_green)
136  place_objects_w_cartesian_CS(my_world=my_world, my_scene=my_scene,
137  my_screen=my_tangent_screen_blue)
138 
139  # place objects with 2D perimetric coordinates on the tangent screens
140  place_objects_w_perimetric_CS(my_world=my_world, my_scene=my_scene,
141  my_tangent_screen=my_tangent_screen_white, my_ecc=9.0)
142  place_objects_w_perimetric_CS(my_world=my_world, my_scene=my_scene,
143  my_tangent_screen=my_tangent_screen_yellow, my_ecc=9.0)
144  place_objects_w_perimetric_CS(my_world=my_world, my_scene=my_scene,
145  my_tangent_screen=my_tangent_screen_orange, my_ecc=9.0)
146  place_objects_w_perimetric_CS(my_world=my_world, my_scene=my_scene,
147  my_tangent_screen=my_tangent_screen_green, my_ecc=9.0)
148  place_objects_w_perimetric_CS(my_world=my_world, my_scene=my_scene,
149  my_tangent_screen=my_tangent_screen_blue, my_ecc=9.0)
150 
151  my_world.add_scene(my_scene)
152  my_world.write()
153 
154 
155 if __name__ == "__main__":
156  main()
def place_objects_w_perimetric_CS(my_world, my_scene, my_tangent_screen, my_ecc)
def place_objects_w_cartesian_CS(my_world, my_scene, my_screen)
def LaunchThe3DWorld(jsonFileCategory="Externals")
Definition: SystemUtils.py:182